package com.ly.honor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.dto.GoodsAppraiseCreateDTO;
import com.ly.honor.entity.vo.GoodsAppraiseQueryVO;
import com.ly.honor.service.GoodsAppraiseService;
import com.ly.honor.service.GoodsOrderService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 李某人
 * @Date 2023/4/5 2:30
 * @Version 1.0
 */
@RestController
@Validated
@Api(tags = "商品评论管理")
@RequestMapping("goodsAppraise")
public class GoodsAppraiseController {

    private GoodsAppraiseService goodsAppraiseService;

    private GoodsOrderService goodsOrderService;

    public GoodsAppraiseController(GoodsAppraiseService goodsAppraiseService,GoodsOrderService goodsOrderService) {
        this.goodsAppraiseService = goodsAppraiseService;
        this.goodsOrderService = goodsOrderService;
    }

    @ApiOperation("分页查询")
    @GetMapping("getGoodsAppraisePage/{pageNum}/{pageSize}/{goodsId}")
    public Result getGoodsAppraisePage(@PathVariable Integer pageNum,
                                       @PathVariable Integer pageSize,
                                       @PathVariable Integer goodsId){
        Page<GoodsAppraiseQueryVO> goodsAppraiseQueryVOPage  = goodsAppraiseService.getGoodsAppraisePage(pageNum,pageSize,goodsId);
        return Result.ok(goodsAppraiseQueryVOPage);
    }

    @ApiOperation("商品评论数量")
    @GetMapping("getGoodsAppraiseCount/{goodsId}")
    public Result getGoodsAppraiseCount(@PathVariable Integer goodsId){
        Integer goodsAppraiseCount = goodsAppraiseService.getGoodsAppraiseCount(goodsId);
        return Result.ok(goodsAppraiseCount);
    }

    @ApiOperation("新增2级评论")
    @PostMapping("addGoodsAppraise")
    public Result addGoodsAppraise(@RequestBody GoodsAppraiseCreateDTO goodsAppraiseCreateDTO, HttpServletRequest request){
        goodsAppraiseService.addGoodsAppraise(goodsAppraiseCreateDTO,request);
        return Result.ok();
    }

    @ApiOperation("新增1级评论")
    @PostMapping("addOneAppraise")
    public Result addOneAppraise(@RequestBody GoodsAppraiseCreateDTO goodsAppraiseCreateDTO, HttpServletRequest request){
        goodsAppraiseService.addOneAppraise(goodsAppraiseCreateDTO,request);
        return Result.ok();
    }
}
